package com.lan.mock13.guosai.t1;

import java.util.*;


class Node {
	public int num, cost;
	public Node(int num, int cost) {
		this.num = num;
		this.cost = cost;
	}
}



public class Main {
	public static void main(String[] args) {
		List<Node> list = new ArrayList<>();
		list.add(new Node(0, 6));
		list.add(new Node(1, 2));
		list.add(new Node(2, 5));
		list.add(new Node(3, 5));
		list.add(new Node(4, 4));
		list.add(new Node(5, 5));
		list.add(new Node(6, 6));
		list.add(new Node(7, 3));
		list.add(new Node(8, 7));
		list.add(new Node(9, 6));
		
		
		Collections.sort(list,(a, b) -> {
			if (a.cost != b.cost) {
				return a.cost - b.cost;
			} else {
				return b.num - a.num;
			}
		});
		
		int m = 300;
		List<Integer> v = new ArrayList<>();
		for (Node e: list) {
			int cost = e.cost;
			int num = e.num;
			int t = 0;
			if (m > cost * 10) {
				m -= (cost * 10);
				t = 10;
			} else {
				t = m / cost;
				m = 0;
			}
			for (int j = 0; j < t; j ++) {
				v.add(num);
			}
			if (m == 0) {
				break;
			}
		}
		
		v.sort((a, b) ->{
			return b - a;
		});
		StringBuilder sb = new StringBuilder();
		for (int num: v) {
			sb.append((char)(num + '0'));
		}
		System.out.println(sb.toString());
	}

}